import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import Nprogress from 'nprogress'

import 'nprogress/nprogress.css'
Nprogress.configure({showSpinner:false})


Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  Nprogress.start()

  document.title = to.meta && to.meta.title
  
  var token = localStorage.getItem('token')

  if (to.path == '/footer/list' || to.path == '/footer/mine') {
    if (token) {
      next()
      console.log('bbb');
    } else {
      next('/login')
      console.log('aaa');
    }
  } else {
    next()
  }
})

router.afterEach((to, from) => {
  Nprogress.done()
})

export default router
